<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多留言板</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            max-width: 1200px;
            padding: 20px;
            background: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            overflow: hidden;
        }
        .input-section {
            width: 100%;
            max-width: 800px;
            margin-bottom: 20px;
            background: #f9f9f9;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            transition: box-shadow 0.3s ease;
        }
        .input-section:hover {
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
        }
        .board-selector {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
        }
        .board-selector select {
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
            color: #333;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .board-selector select:hover {
            background-color: #e1f5fe;
        }
        .input-section textarea {
            width: 100%;
            max-width: 100%;
            margin-bottom: 10px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 16px;
            color: #333;
            resize: none;
            transition: border-color 0.3s ease;
        }
        .input-section textarea:focus {
            border-color: #007bff;
        }
        .input-section button {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }
        .input-section button:hover {
            background-color: #0056b3;
        }
        .boards {
            display: flex;
            justify-content: space-around;
            width: 100%;
            max-width: 1200px;
        }
        .board {
            flex: 1;
            margin: 0 10px;
            background: #f9f9f9;
            border: 1px solid #ccc;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            transition: box-shadow 0.3s ease;
        }
        .board:hover {
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
        }
        .board h2 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }
        .board .messages {
            max-height: 300px;
            overflow-y: auto;
            padding: 10px;
            background-color: #e1f5fe;
            border: 1px solid #b3e5fc;
            border-radius: 10px;
        }
        .board .message {
            padding: 10px;
            margin-bottom: 10px;
            background-color: #e1f5fe;
            border: 1px solid #b3e5fc;
            border-radius: 5px;
            font-size: 14px;
            color: #333;
            transition: background-color 0.3s ease;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .board .message:hover {
            background-color: #d0e8f9;
        }
        .board .message button {
            padding: 5px 10px;
            background-color: #ff4d4d;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 12px;
            transition: background-color 0.3s ease;
        }
        .board .message button:hover {
            background-color: #ff1a1a;
        }
        .board .messages::-webkit-scrollbar {
            width: 8px;
        }
        .board .messages::-webkit-scrollbar-thumb {
            background-color: #ccc;
            border-radius: 4px;
        }
        .board .messages::-webkit-scrollbar-track {
            background-color: #f1f1f1;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="input-section">
        <div class="board-selector">
            <label for="boardSelect">选择留言板：</label>
            <select id="boardSelect">
                <option value="board1">留言板1</option>
                <option value="board2">留言板2</option>
                <option value="board3">留言板3</option>
            </select>
        </div>
        <form id="messageForm">
            <textarea id="messageInput" placeholder="请输入留言..." rows="4"></textarea>
            <button type="submit">提交留言</button>
        </form>
        <button id="clearAllButton">Clear All Messages</button>
    </div>
    <div class="boards">
        <div class="board" id="board1">
            <h2>留言板1</h2>
            <div class="messages" id="messages1"></div>
        </div>
        <div class="board" id="board2">
            <h2>留言板2</h2>
            <div class="messages" id="messages2"></div>
        </div>
        <div class="board" id="board3">
            <h2>留言板3</h2>
            <div class="messages" id="messages3"></div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', () => {
        const messageForm = document.getElementById('messageForm');
        const messageInput = document.getElementById('messageInput');
        const boardSelect = document.getElementById('boardSelect');
        const boards = ['board1', 'board2', 'board3'];
        const allBoards = JSON.parse(localStorage.getItem('allBoards')) || {
            board1: [],
            board2: [],
            board3: []
        };

        function displayMessages() {
            boards.forEach(board => {
                const messagesDiv = document.getElementById(`messages${board.slice(-1)}`);
                const messages = allBoards[board];
                messagesDiv.innerHTML = '';
                messages.forEach((message, index) => {
                    const messageElement = document.createElement('div');
                    messageElement.classList.add('message');
                    messageElement.innerHTML = `
                        ${message}
                        <button class="delete-button" data-board="${board}" data-index="${index}">删除</button>
                    `;
                    messagesDiv.appendChild(messageElement);
                });
            });
        }

        displayMessages();

        messageForm.addEventListener('submit', (e) => {
            e.preventDefault();
            const message = messageInput.value.trim();
            if (message) {
                const currentBoard = boardSelect.value;
                allBoards[currentBoard].push(message);
                localStorage.setItem('allBoards', JSON.stringify(allBoards));
                displayMessages();
                messageInput.value = '';
            }
        });

        document.addEventListener('click', (e) => {
            if (e.target.classList.contains('delete-button')) {
                const board = e.target.getAttribute('data-board');
                const index = e.target.getAttribute('data-index');
                allBoards[board].splice(index, 1);
                localStorage.setItem('allBoards', JSON.stringify(allBoards));
                displayMessages();
            }
        });

        document.getElementById('clearAllButton').addEventListener('click', () => {
            const board = boardSelect.value;
            allBoards[board] = [];
            localStorage.setItem('allBoards', JSON.stringify(allBoards));
            displayMessages();
        });
    });
</script>
</body>
</html>
